//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.liy.framework.common.office;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Word2PdfUtil {
    protected static Logger log = LoggerFactory.getLogger(Word2PdfUtil.class);
    static final int wdDoNotSaveChanges = 0;
    static final int wdFormatPDF = 17;

    public Word2PdfUtil() {
    }

    public static boolean word2pdf(String source, String target) throws Exception {
        log.info("Word转PDF开始启动...");
        long start = System.currentTimeMillis();
        ActiveXComponent app = null;

        boolean var10;
        try {
            app = new ActiveXComponent("Word.Application");
            app.setProperty("Visible", false);
            Dispatch docs = app.getProperty("Documents").toDispatch();
            log.info("打开文档：" + source);
            Dispatch doc = Dispatch.call(docs, "Open", new Object[]{source, false, true}).toDispatch();
            log.info("转换文档到PDF：" + target);
            File tofile = new File(target);
            if (!tofile.getParentFile().exists()) {
                tofile.getParentFile().mkdirs();
            }

            if (tofile.exists()) {
                tofile.delete();
            }

            Dispatch.call(doc, "SaveAs", new Object[]{target, 17});
            Dispatch.call(doc, "Close", new Object[]{false});
            long end = System.currentTimeMillis();
            log.info("转换完成，用时：" + (end - start) + "ms");
            var10 = true;
        } catch (Exception var14) {
            log.info(source + ">>>>Word转PDF出错：" + var14.getMessage());
            throw new Exception("Word转PDF出错：" + var14.getMessage(), var14);
        } finally {
            if (app != null) {
                app.invoke("Quit", 0);
            }

        }

        return var10;
    }

    public static void main(String[] args) {
        try {
            word2pdf("C:\\Temp\\xml\\abc.doc", "C:\\Temp\\xml\\abc.pdf");
        } catch (Exception var2) {
            var2.printStackTrace();
        }

    }
}
